import babelpolyfill from 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
//import './assets/theme/theme-green/index.css'
// 路由
import VueRouter from 'vue-router'
// 状态管理工具
import store from './vuex/store'
import Vuex from 'vuex'
//import NProgress from 'nprogress'
//import 'nprogress/nprogress.css'
import routes from './routes'
// import Mock from './mock'
// Mock.bootstrap();
import 'font-awesome/css/font-awesome.min.css'
import axios from "axios";
axios.defaults.baseURL="http://127.0.0.1:8081"
// 给Vue设置一个属性叫做$http
Vue.prototype.$http=axios

Vue.use(ElementUI)
Vue.use(VueRouter)
Vue.use(Vuex)

//NProgress.configure({ showSpinner: false });

const router = new VueRouter({
  routes
})

/*
  拦截器:
    axios 的请求拦截器
      在里面做配置，在请求头里面携带 token
    axios 的响应拦截器
      在里面做配置，如果登录过期就返回登录页面
 */
// axios.interceptors.request.use(config => {
//   // 获取 localStorage里的 token
//   let token = localStorage.getItem("token");
//   // 判断 token
//     if (token){
//       config.headers.TOKEN = token;
//     }
//     return config;
// },error => {
//   return Promise.reject(error);
// })

// axios.interceptors.response.use(resp => {
//   let {success,message} = resp.data;
//   if (!success && message === "noLogin"){
//     router.push({path:'/login'});
//   }
//   if (!success && message === "noPermission"){
//     router.push({path:'/401'});
//   }
//     return resp;
//
// },error => {
//   return Promise.reject(error);
// })

// router.beforeEach((to, from, next) => {
//   //NProgress.start();
//   if (to.path == '/login') {
//     localStorage.removeItem('user');
//   }
//   let user = JSON.parse(localStorage.getItem('user'));
//   if (!user && to.path != '/login') {
//     next({ path: '/login' })
//   } else {
//     next()
//   }
// })

//router.afterEach(transition => {
//NProgress.done();
//});

new Vue({
  //el: '#app',
  //template: '<App/>',
  router,
  store,
  //components: { App }
  render: h => h(App)
}).$mount('#app')

